package com.easy.service.impl;

import com.easy.zhu.LogMethod;
import com.easy.bean.AdoptBean;
import com.easy.mapper.AdoptBeanDao;
import com.easy.service.AdoptBeanService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
//实现类，实现接口中的方法
@Service
public class AdoptServiceImpl implements AdoptBeanService {
    @Autowired//依赖注入
    AdoptBeanDao adoptBeanDao;
    @Override
    @LogMethod(serviceName = "用户添加处理")
    public AdoptBean add(AdoptBean adoptBean) {
        //新增数据
        adoptBeanDao.add(adoptBean);
        //通过主键查询数据库里面的数据
        AdoptBean result=adoptBeanDao.one(adoptBean.getId());
        return result;
    }

    @Override
    @LogMethod(serviceName = "用户删除处理")
    public int del(Integer id) {
        return adoptBeanDao.del(id);
    }

    @Override
    @LogMethod(serviceName = "用户修改处理")
    public AdoptBean edit(AdoptBean adoptBean) {
        adoptBeanDao.edit(adoptBean);
        AdoptBean result=adoptBeanDao.one(adoptBean.getId());//重新查询一遍
        return result;
    }

    @Override
    @LogMethod(serviceName = "用户查询处理")
    public List<AdoptBean> all(AdoptBean adoptBean) {

        return adoptBeanDao.all(adoptBean);
    }

    @Override
    @LogMethod(serviceName = "用户查询处理")
    public AdoptBean one(Integer id) {
        return adoptBeanDao.one(id);
    }

    @Override
    @LogMethod(serviceName = "用户分页处理")
    public void page(Page page, AdoptBean adoptBean) {
        int count=adoptBeanDao.pageCount(adoptBean);//查询数据总条数
        Object data=adoptBeanDao.page(page,adoptBean);//查询当前页的数据
        page.setCount(count);//设置总条数
        page.setData(data);//设置当前页的数据

    }
}























